﻿namespace InkType.ViewModel

open System
open System.Windows
open System.Windows.Data

#nowarn "62"

module Dp =
    type MetaFlags = FrameworkPropertyMetadataOptions

    type ('a, 'owner) Meta when 'owner :> DependencyObject private (meta : FrameworkPropertyMetadata) =
        new (initval : 'a) =
            Meta (FrameworkPropertyMetadata (initval))

        new (initval : 'a, flags : MetaFlags) =
            Meta (FrameworkPropertyMetadata (initval, flags))

        new (initval : 'a, flags : MetaFlags, propChanged) =
            Meta (
                FrameworkPropertyMetadata (
                    initval, flags,
                    PropertyChangedCallback (fun d e -> propChanged (d :?> 'owner) (e.OldValue :?> 'a, e.NewValue :?> 'a))))

        new (initval : 'a, flags : MetaFlags, propChanged, coerce : _ -> _ -> 'a) =
            Meta (
                FrameworkPropertyMetadata (
                    initval, flags,
                    PropertyChangedCallback (fun d e -> propChanged (d :?> 'owner) (e.OldValue :?> 'a, e.NewValue :?> 'a)),
                    CoerceValueCallback (fun d v -> coerce (d :?> 'owner) (v :?> 'a) |> box)))

        new (initval : 'a, flags : MetaFlags, propChanged, coerce : _ -> _ -> 'a, forbidAnimation) =
            Meta (
                FrameworkPropertyMetadata (
                    initval, flags,
                    PropertyChangedCallback (fun d e -> propChanged (d :?> 'owner) (e.OldValue :?> 'a, e.NewValue :?> 'a)),
                    CoerceValueCallback (fun d v -> coerce (d :?> 'owner) (v :?> 'a) |> box),
                    forbidAnimation))

        new (initval : 'a, flags : MetaFlags, propChanged, coerce : _ -> _ -> 'a, forbidAnimation, initTrigger) =
            Meta (
                FrameworkPropertyMetadata (
                    initval, flags,
                    PropertyChangedCallback (fun d e -> propChanged (d :?> 'owner) (e.OldValue :?> 'a, e.NewValue :?> 'a)),
                    CoerceValueCallback (fun d v -> coerce (d :?> 'owner) (v :?> 'a) |> box),
                    forbidAnimation, initTrigger))

        new (initval : 'a, propChanged) =
            Meta (
                FrameworkPropertyMetadata (
                    initval,
                    PropertyChangedCallback (fun d e -> propChanged (d :?> 'owner) (e.OldValue :?> 'a, e.NewValue :?> 'a))))

        new (initval : 'a, propChanged, coerce : _ -> _ -> 'a) =
            Meta (
                FrameworkPropertyMetadata (
                    initval,
                    PropertyChangedCallback (fun d e -> propChanged (d :?> 'owner) (e.OldValue :?> 'a, e.NewValue :?> 'a)),
                    CoerceValueCallback (fun d v -> coerce (d :?> 'owner) (v :?> 'a) |> box)))

        member x.WpfMeta = meta

    let inline reg<'a, 'owner when 'owner :> DependencyObject> name (meta : ('a, 'owner) Meta) =
        DependencyProperty.Register (
            name, typeof<'a>, typeof<'owner>, meta.WpfMeta)

    let inline regr<'a, 'owner when 'owner :> DependencyObject> name (meta : ('a, 'owner) Meta) =
        DependencyProperty.RegisterReadOnly (
            name, typeof<'a>, typeof<'owner>, meta.WpfMeta)


